package com.itlaobing.dev;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet( "/general/*" )
public class GeneralServlet extends HttpServlet {

	private static final long serialVersionUID = -5747264846365275367L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) 
			throws ServletException, IOException {
		
		String uname = req.getParameter( "username" ); // <input type="text" name="username" >
		System.out.println( "username : " + uname );
		
		String passwd = req.getParameter( "password" ); // <input type="password" name="password" >
		System.out.println( "password : " + passwd );
		
		String method = req.getMethod(); // 通过 请求对象(req) 来获取本次请求所采用的请求方式(即采用了那种HTTP动作)
		System.out.println( method );
		// 在控制台（Console）中输出信息
		System.out.println( "general servlet : service" );
		// 获得可以向响应对象中输出数据的字符输出流
		PrintWriter w = resp.getWriter();
		// 向响应对象中输出HTML片段（最终发送到Web客户端）
		w.println( "<h1 align='center'>I am a general servlet .</h1>" );
		w.println( "<h3 align='center'>request method ( HTTP action ) : " + method + " .</h3>" );
	}

}
